/*
 * Copyright (c) 2005-2018. YingQi Anime Technology Co. Ltd. All rights reserved.
 * FileName: PropertiesUtils.java
 * Author:   LL
 * Date:     2018年4月9日 上午11:06:59
 * Description: //模块目的、功能描述
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.sfang.common.util.configuration;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 〈一句话功能简述〉<br>
 * 〈功能详细描述〉
 *
 * @author LL
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class PropertiesUtils {

    private static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);

    private Configuration config;

    private PropertiesUtils() {
    }

    private PropertiesUtils(String fileName) {
        try {
            config = new PropertiesConfiguration(fileName);
        } catch (ConfigurationException e) {
            logger.error("Failed to initialize the configuration file: {}", fileName, e);
        }
    }

    public static PropertiesUtils create(String fileName) {
        return new PropertiesUtils(fileName);
    }

    public byte getByte(String key) {
        return config.getByte(key);
    }

    public byte getByte(String key, byte defaultValue) {
        return config.getByte(key, defaultValue);
    }

    public double getDouble(String key) {
        return config.getDouble(key);
    }

    public double getDouble(String key, double defaultValue) {
        return config.getDouble(key, defaultValue);
    }

    public float getFloat(String key) {
        return config.getFloat(key);
    }

    public float getFloat(String key, float defaultValue) {
        return config.getFloat(key, defaultValue);
    }

    public int getInt(String key) {
        return config.getInt(key);
    }

    public int getInt(String key, int defaultValue) {
        return config.getInt(key, defaultValue);
    }

    public long getLong(String key) {
        return config.getLong(key);
    }

    public long getLong(String key, long defaultValue) {
        return config.getLong(key, defaultValue);
    }

    public boolean getBoolean(String key) {
        return config.getBoolean(key);
    }

    public boolean getBoolean(String key, boolean defaultValue) {
        return config.getBoolean(key, defaultValue);
    }

    public String getString(String key) {
        return config.getString(key);
    }

    public String getString(String key, String defaultValue) {
        return config.getString(key, defaultValue);
    }

}
